#!/bin/bash

# 定义一个函数切换到 root 用户
change_root() {
    if [ "$EUID" -ne 0 ]; then
        echo -n "请输入开机密码："
        read -s password
        echo
        echo "$password" | sudo -S "$@"
    else
        "$@"
    fi
}
# 使用 change_root 函数来运行命令
# change_root echo "This is run as root"

#获取普通用户目录
home_path() {
  cd "/home/$this_user" || exit
}
desktop_path() {
  if [ -d "/home/$this_user/桌面" ]; then
    cd "/home/$this_user/桌面" || exit
  elif [ -d "/home/$this_user/desktop" ]; then
    cd "/home/$this_user/desktop" || exit
  fi
}

# download_file下载方法
download_file() {
  change_root
  local download_flag=$1
  local down_format_flag=$2
  downzip_tmp="/tmp/$download_flag/"
  if [[ $down_format_flag == "act_zip" || $down_format_flag == "deb_zip" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.zip"
  elif [[ $down_format_flag == "deb" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.deb"
  elif [[ $down_format_flag == "deb_rar" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.deb"
  fi
  mkdir -p "$downzip_tmp"
  download_link=$(get_download_link "$download_flag")
  echo "$download_flag"
  echo "$down_format_flag"
  echo "$download_tmp_file"
  echo "$download_link"
  if ! wget --no-check-certificate -O "$download_tmp_file" "$download_link"; then
    echo -e "$red 下载文件失败..$none" && exit 1
  fi
  cd "$downzip_tmp" || exit
  if [[ $down_format_flag == "act_zip" || $down_format_flag == "deb_zip" ]]; then
    unzip -o "$download_flag".zip
    if [[ $down_format_flag == "deb_zip" ]]; then
      sudo chmod 777 -- ./*.deb
      sudo dpkg -i -- ./*.deb
      sudo dpkg -i -- ./*.deb
    elif [[ $down_format_flag == "act_zip" ]]; then
      sudo cp "$downzip_tmp"/.kyinfo "$downzip_tmp"/LICENSE /etc/
      echo -e "$red 应该是修改完了，关闭之前的激活页面，重新打开激活页面激活一下吧。$none \n"
    fi
  elif [[ $down_format_flag == "deb" ]]; then
    sudo chmod 777 -- ./*.deb
    sudo dpkg -i -- ./*.deb
  fi
  if [ "$download_flag" == "dfonts" ]; then
    echo -e "$red 应该是下载并安装成功了，右键ttf文件在字体查看器中打开，右上角有安装按钮。$none \n"
  fi
}
# 下载地址
# 下载地址获取
get_download_link() {
  local download_flag="$1"

  case $download_flag in
    "wx_mips_depend")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/Wechat/Mips/wechat-mips2.0-depend.zip"
      fi
      ;;
    "act_v10_0710")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_0710.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710.zip"
      fi
      ;;
    "act_v10_0710_2")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710_2.zip"
      fi
      ;;
    "act_v10_1026")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_1026.zip"
      fi
      ;;
    "act_v10_1026_2")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026_2.zip"
      fi
      ;;
    "act_v10_2107")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_mips_2107.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_arm_2107.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_x86_2107.zip"
      fi
      ;;
    "act_v10_2203")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_mips_2203.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_arm_2203.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_v10_x86_2203.zip"
      fi
      ;;
    "act_v10sp1_2107")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_mips_2107.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_arm_2107.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_x86_2107.zip"
      fi
      ;;
    "act_v10sp1_2203")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_mips_2203.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_arm_2203.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_x86_2203.zip"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_loongarch_2203.zip"
      fi
      ;;
    "act_v10sp1_2303")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_mips_2303.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_arm_2303.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_x86_2303.zip"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_loongarch_2303.zip"
      fi
      ;;
    "kelu_xuke")
      case $sys_str in
        "mips64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_mips.zip"
          ;;
        "aarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_arm.zip"
          ;;
        "x86_64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_x86.zip"
          ;;
        "loongarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_loongarch64.zip"
          ;;
      esac
      ;;
    "kelu_zifu_2303")
      case $sys_str in
        "mips64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_mips.zip"
          ;;
        "aarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_arm.zip"
          ;;
        "x86_64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_x86.zip"
          ;;
        "loongarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_loongarch.zip"
          ;;
      esac
      ;;
    "vscode")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/code/VScode/code_1.82.2-1694671436_arm64.deb"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/code/VScode/code_1.82.2-1694671812_amd64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "wechat_beta")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/wechat-beta_1.0.0.241_arm64.deb"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/wechat-beta_1.0.0.241_amd64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/wechat-beta_1.0.0.241_loongarch64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "wps_personal")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_arm64.deb?t=1713517548&k=76df4b259943bc907e9fc26f152fd800"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_amd64.deb?t=1713517623&k=556c0e86005afcd6390bc7b1df0bfe37"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_loongarch64.deb?t=1713517677&k=32ca31da653110df7a218c74b41b8cb9"
      elif [ "$sys_str" == "mips64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_mips64el.deb?t=1713517643&k=0ac19eea9b1f467ee5a9f6f91157565f"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
      
    "canon2900")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/cups/Canon/captdriver_1.0.1_mips64el.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/cups/Canon/captdriver_1.0.1_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "bentu7105dn")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10%2Bsv_mips64el.rar"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10_amd64_deb.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10%2Bsv_arm64.rar"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10_loongarch64_deb.zip"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "todesk")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://newdl.todesk.com/linux/todesk-v4.3.1.0-arm64.deb"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://newdl.todesk.com/linux/todesk-v4.3.1.0-amd64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "sunlogin")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_mips.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        if [ "$cpu_name" == "Kirin990" ]; then
          if [ "$os_version_small" == "40222" ]; then
            echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunlogin-990-2203.zip"
            #TUDO
          else
            echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin990_1228.deb"
          fi
        elif [ "$cpu_name" == "HUAWEI Kirin 9006C" ]; then
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin9a0_20220221.deb"
      else
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_arm64.deb"
      fi
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_x86_64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "wx_2.1.4")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.4-1_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.4-1_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.4-1_loongarch64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "wx_2.1.9")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.9_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.9_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.9_loongarch64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "tencent_metting")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/bb4001c715553579a8b3e496233331d4/TencentMeeting_0300000000_3.19.0.401_x86_64_default.publish.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/0f96a97b0aaea9b9d5d2c2b912ede656/TencentMeeting_0300000000_3.19.0.401_arm64_default.publish.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/e32241120138358ec28fbedeceef631c/TencentMeeting_0300000000_3.19.0.401_loongarch64_default.publish.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "tencent_linuxqq")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/db6c41a0/linuxqq_3.2.7-23159_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/db6c41a0/linuxqq_3.2.7-23159_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/db6c41a0/linuxqq_3.2.7-23159_loongarch64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        if [[ $version_flag == 'V10' ]];then
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/QQ/Mips/linuxqq_2.0.0-b4_mips64el.deb"
        else
          echo "https://dldir1.qq.com/qqfile/qq/QQNT/db6c41a0/linuxqq_3.2.7-23159_mips64el.deb"
        fi
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "aliyunpan")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/aliyun/aliyun_amd.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/aliyun/aliyun_arm.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "notepad")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/notepad/notepad--v2.10-kinly-spv10-x64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/notepad/notepad--v2.10-kinly-spv10-arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "lxmusic")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/lxmusic/lx-music-desktop_2.7.0_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/lxmusic/lx-music-desktop_2.7.0_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "bilibilidl")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/bilibili/bilibili_1.13.2-1_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/bilibili/bilibili_1.13.2-1_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "easyconnect")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/easyconnect/EasyConnect_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "sys_update_v10_0710")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_mips64el.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "sys_update_v10_2101")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_mips64el.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "usr")
      echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/deb_change/usr.zip"
      ;;
    "mk_iso")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-5_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-5_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-1_mips64el.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-1_loongarch64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "lanxin")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://cdn-lxs3.b.qianxin.com/lxpmcpublic/7d3e3c9e-079c-42d4-af98-51eca73ed82a.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    *)
      echo "暂不支持" && exit 1
      ;;
  esac
}
# 源、商店错误处理
softcenter_repair() {
  change_root
  local software_repair_flag=$1
  if [ "$software_repair_flag" == 'soft_GPG' ]; then
    #源GPG错误
    sudo mv /var/lib/apt/lists /var/lib/apt/list_"$timestamp"
    sudo mkdir -p /var/lib/apt/lists/partial
    sudo apt clean
    sudo apt update
  elif [ "$software_repair_flag" == 'soft_lock' ]; then
    #源报头为0
    sudo rm -rf /var/lib/apt/lists/*
    sudo apt update
  elif [ "$software_repair_flag" == 'soft_install_fail' ]; then
    #软件安装失败
    sudo apt install --fix-broken
    sudo apt install -f
    sudo apt-get update --fix-missing
  elif [ "$software_repair_flag" == 'soft_wrong_code_soft' ]; then
    #软件商店报错--重装软件商店
    sudo apt update
    sudo apt install --fix-broken
    sudo apt install -f
    sudo apt install -y kylin-software-center --reinstall
    sudo rm /var/lib/dpkg/updates/*
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo dpkg --configure -a
    sudo apt update
  elif [ "$software_repair_flag" == 'soft_wrong_code' ]; then
    #软件商店报错--不重装软件商店
    sudo apt update
    sudo apt install --fix-broken
    sudo apt install -f
    sudo rm /var/lib/dpkg/updates/*
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo dpkg --configure -a
    sudo apt update
  elif [ "$software_repair_flag" == '0710_cantopen' ]; then
    #mips老版本如0710安装最新商店报错
    # sudo apt-cache show kylin-software-center
    sudo apt  install  kylin-software-center=4.5.54kord
    sudo apt update
  fi
}



# 获取系统架构
sys_str=$(uname -m)
# 修复系统软件标志位
software_repair_flag=''
# 文件标志位
file_flag=0
# 下载标志位
download_flag=''
# 获取普通用户
this_user=$(users | awk '{print $1}')
# 获取当前时间
timestamp=$(date +%Y-%m-%d_%H_%M_%S)
# 获取芯片，$1=$1用于去除字段前后的空格或制表符。
cpu_name=$(lscpu | grep "型号名称" | awk -F "：" '{print $2}' | awk '{$1=$1;print}')
# 获取根目录
#sys_root=$(lsblk -o NAME,MOUNTPOINT -P | grep -w / | awk -F" " '{print $1}' | awk -F"=" '{print $2}' | awk -F"\"" '{print $2}')
sys_root=$(lsblk -o NAME,MOUNTPOINT | grep -w "/" | awk '{sub("├─", "", $1); print $1}')
# 获取硬盘
my_disk=$(lsblk -d | grep disk | awk '{print $1}')
# 获取当前文件夹名NF取最后一个--如/home/leeyc/桌面，则桌面
# dir=$(pwd|awk -F "/" '{print $NF}')
os_version_small=$(cat /etc/kylin-build | grep -w "buildid" | awk -F" " '{print $2}')       # 获取buildid，比如2203-x86=31950，2303-x86=41998
# #确认当前系统是否为V10桌面版本
version_flag=$(cat /etc/kylin-build | awk '{print $2}' | awk 'NR==1')

get_pause() {
  SAVEDSTTY=$(stty -g)
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2>/dev/null
  stty -raw
  stty echo
  stty "$SAVEDSTTY"
}

findname() {
  change_root
  local file_flag=$1
  if [ "$file_flag" == 'file_case' ]; then
    read -r -p "$(echo -e "请输入要查找的文件名:")" name
    sudo find /home/ -name "$name*" -print | tee find"$name".txt
  elif [ "$file_flag" == 'file_nocase' ]; then
    read -r -p "$(echo -e "请输入要查找的文件名:")" name
    sudo find /home/ -iname "$name*" -print | tee find"$name".txt
  elif [ "$file_flag" == 'file_content' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" content
    sudo grep -rl "$content" /home /data | tee find"$content".txt
  elif [ "$file_flag" == 'file_own_content' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" content
    read -r -p "$(echo -e "请输入要查找的位置，多个位置用空格隔开:")" loc
    sudo grep -rl "$content" "$loc" | tee find"$content".txt
  elif [ "$file_flag" == 'soft_source' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" soft_source
    sudo apt search "$soft_source"
  elif [ "$file_flag" == 'soft_local_all' ]; then
    echo -e "安装的软件包输出到文件中"
    sudo dpkg --get-selections | tee installsoftware.txt
  elif [ "$file_flag" == 'soft_local' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" soft_local
    sudo dpkg --get-selections | grep "$soft_local"
  fi
}
get_pause() {
  SAVEDSTTY=$(stty -g)
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2>/dev/null
  stty -raw
  stty echo
  stty "$SAVEDSTTY"
}



# 显示主菜单的函数
main_menu() {
    while true; do
        echo " 。。。。。系统环境异常修复。。。。。
。。。。。我的电脑右键属性--FT2000属于ARM、3A4000属于mips。。。。。
。。。。。注意很多修复相关的是要在v10上用，有的是v10sp1可用，尽量询问之后再用。。。。。
。。。。。李林自己的选项-按11。。。。。"
        echo " "
        echo "主菜单"
        
        PS3=$'\n请选择一个选项：'
        options=(
        "1、系统信息-备份系统日志-系统运行信息"  
        "2、修复系统V10用-激活-黑屏-系统软件等"  
        "3、软件商店问题"  
        "4、应用软件"  
        "5、打印机相关"  
        "6、其他功能"
        "7、服务器相关"
		"11、 李林自己的选项-按11"
        "0、退出")
        select option in "${options[@]}"; do
            case $REPLY in
                1) system-message; break;;   # 系统信息、备份系统日志、系统运行信息
                2) system-repair; break;;   # 当用户选择女时，调用女子菜单函数并跳出select循环
                3) software_repair; break;;   # 当用户选择其他菜单时，调用其他子菜单函数并跳出select循环
				4) software_app; break;;
				5) software_printer; break;;
				6) software_other; break;;
				7) software_server; break;;
				11) peter; break;;
                0) exit 0;;   # 当用户选择退出时，退出脚本
                *) echo "无效的选项。请重试。"; continue;;   # 处理无效输入，提示重试
            esac

            # 检查是否需要返回主菜单-按“00000”
            #if $return_to_main; then
                return_to_main=false
            #    break
            #fi
        done
    done
}


# 一、系统信息-备份系统日志-系统运行信息：system-message
system-message() {
    while true; do
	    return_to_main=false
        echo "系统信息-备份系统日志-系统运行信息"
		options=(
		"1、备份系统信息到桌面" 
		"2、备份系统日志到桌面" 
		"3、查看系统运行信息"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) system-message-bak; break;;
                2) system-message-logs-bak; break;;
                3) system-message-run; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-message-bak(){
  change_root
  version=$(sudo cat /etc/os-release | grep -w "VERSION" | awk -F"=" '{print $2}')              #系统版本
  version_build=$(sudo cat /etc/kylin-build | grep -w "Build" | awk -F" " '{print $2}')         #build号
  version_id=$(sudo cat /etc/kylin-build | grep -w "buildid:" | awk -F" " '{print $2}')         #版本id
  version_stone=$(sudo cat /etc/.kyinfo | grep -w "milestone" | awk -F"=" '{print $2}')         #版本号
  kylin_serial=$(sudo kylin_serial)                                                             #服务序列号
  kyregistration_key=$(sudo kylin_gen_register)                                                 #注册码
  if [ -f "/etc/.kyactivation" ]; then
    kyactivation_key=$(sudo cat /etc/.kyactivation 2>/dev/null)                                 #激活码
  else
    kyactivation_key=None
  fi                                                                     
  system_serial_number=$(sudo cat /sys/class/dmi/id/product_serial)                             #主机序列号
  main_bord=$(sudo dmidecode |grep -A9 "System Information" | awk '/UUID:/{print $2}')          #主板序列号
  #blk_serials=$(sudo lsblk -d -o NAME,SERIAL,TYPE -P | grep disk)                              #硬盘序列号
  blk_serials=$(sudo udevadm info --query=all --name=/dev/$my_disk | grep ID_SERIAL= | cut -d'=' -f2 | sed 's/ /-/g')
  phy_adapters=$(sudo ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)")           #网卡
  
  # os_version=$(head -n1 /etc/kylin-build |awk '{print $2}')                                   # 获取系统版本
  # cpu_name=Kirin990,2203version=20230310,os_version_small=40222
  echo -e "电脑cpu为: $cpu_name" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统版本为: $version" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统build版本为: $version_build" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统id号为: $version_id" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统版本为: $version_stone" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "服务序列号为：$kylin_serial" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "注册码: $kyregistration_key" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "激活码为: $kyactivation_key" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "主机序列号: $system_serial_number" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "主板序列号：$main_bord" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "硬盘序列号: $blk_serials" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "网卡为: $phy_adapters" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "网卡MAC地址:" | tee -a /home/"$this_user"/桌面/sys_info.txt
  for phy_adapter in $phy_adapters; do
    mac=$(cat /sys/class/net/"$phy_adapter"/address)
    echo "NAME=\"$phy_adapter\" MAC=\"$mac\"" | tee -a /home/"$this_user"/桌面/sys_info.txt
  done
  echo -e "根目录为：$sys_root" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "\n\nwps序列号为：\n" | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
  cat  /opt/kingsoft/wps-office/office6/cfgs/oem.ini | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
  sudo cp  /opt/kingsoft/wps-office/office6/cfgs/oem.ini /home/"$this_user"/桌面/
  sudo chmod 777 /home/"$this_user"/桌面/sys_info.txt 
  sudo chmod 777 /home/"$this_user"/桌面/oem.ini
  echo -e "\n\n" | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
}
system-message-logs-bak(){
  change_root
  sudo tar -czvPf /home/"$this_user"/桌面/log_"$timestamp".tar.gz /var/log
  sudo chmod 777 /home/"$this_user"/桌面/log_"$timestamp".tar.gz
  echo -e "$magenta 找到log_$timestamp.tar.gz这个文件，备份到桌面了，从桌面拷出来发给我$none \n"
}
system-message-run(){
  date | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "占用cpu最高的10个进程是:" | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  ps aux --sort=-%cpu|sed -n '1,11p' | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "占用mem最高的10个进程是:" | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  ps aux --sort=-%mem|sed -n '1,11p' | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "总体内存使用情况是:"  | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  free -h | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "中断情况是:"  | tee -a  /home/"$this_user"/桌面/stat_cpu_mem.txt
  tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt <<< "$(</proc/interrupts)"
  echo  | tee -a  /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo -e "$red 桌面有个stat_cpu_mem.txt文件，可打开查看信息"
  chmod 777 /home/"$this_user"/桌面/stat_cpu_mem.txt
}



# 二、修复系统V10用-激活-黑屏-系统软件等：system-repair
system-repair(){
    while true; do
	    return_to_main=false
        echo "修复系统V10用-激活-黑屏-系统软件等"
		options=(
		"1、激活" 
		"2、桌面任务栏、图标、黑屏、控制面板打不开、关机等相关问题" 
		"3、其他问题修复" 
		"4、系统软件修复" 
		"5、开发盘下修复" 
		"6、系统升级" 
		"7、可能非好用功能" 
		"9、上一级菜单-按“99999”"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
		case $REPLY in
                1) system-repair-activate; break;;
                2) system-repair-boon; break;;
                3) system-repair-desk-other; break;;
				4) system-repair-soft-fix; break;;
				5) system-repair-dev-fix; break;;
				6) system-repair-update; break;;
				7) system-repair-mabe; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-activate(){
    while true; do
	    return_to_main=false
        echo "激活"
		options=(
		"1、二维码灰色、无效序列号-下载对应的kyinfo文件" 
		"2、修复激活提示无法获取硬件信息的错误码0017问题" 
		"3、从V10升级系统到SP1后激活操作系统--要知道原来的序列号" 
		"4、linux命令交互式激活" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
		    case $REPLY in
                1) system-repair-activate1; break;;
                2) sudo rm -rf /etc/.kyhwid && sudo kylin_activation_check; break;;
                3) system-repair-verify; break;;
				4) sudo kylin-system-verify; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-activate1(){
    while true; do
	    return_to_main=false
	    options=(
		"1、安装V10-0710版本" 
		"2、安装V10-1026版本" 
		"3、安装V10-0710-2版本" 
		"4、安装V10-1026-2版本" 
		"5、安装V10-2107版本" 
		"6、安装V10-2203版本" 
		"7、安装V10SP1-2107版本" 
		"8、安装V10SP1-2203版本" 
		"9、安装V10SP1-2303版本" 
		"0、返回上一级菜单-按“99999”")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) download_file act_v10_0710 act_zip; break;;
                2) download_file act_v10_1026 act_zip; break;;
                3) download_file act_v10_0710_2 act_zip; break;;
				4) download_file act_v10_1026_2 act_zip; break;;
				5) download_file act_v10_2107 act_zip; break;;
				6) download_file act_v10_2203 act_zip; break;;
				7) download_file act_v10sp1_2107 act_zip; break;;
				8) download_file act_v10sp1_2203 act_zip; break;;
				9) download_file act_v10sp1_2303 act_zip; break;;
                0) return;;   # 返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-verify(){
  read -p "请输入原来的序列号之后回车：" new_number
  sudo sed -i "/^key=/s/key=[0-9]*/key=${new_number}/" /etc/.kyinfo
  echo -e "关闭所有激活相关的页面，然后重新我的电脑右键属性，重新点激活---二维码，联网状态大部分直接激活，不联网的重新扫码填入激活码"
  cat /etc/.kyinfo | grep "key="
}

system-repair-boon(){
    while true; do
	    return_to_main=false
	    options=(
		"1、V10/SP1-任务栏消失/小键盘及输入法消失" 
		"2、V10/SP1-输密码进不去桌面-怀疑磁盘满了" 
		"3、V10/SP1-垃圾软件清理" 
		"4、V10/SP1-重装卸载残留文件-注:重要文件要备份,用于安或卸软件导致系统问题,且未清理软件垃圾" 
		"5、V10/SP1-关机提示正在升级等" 
		"6、V10/SP1-开机无桌面图标/或显示正在启动caja只有任务栏/开机进tty1-黑屏(命令行),不进桌面" 
		"7、V10-提示框：面板载入问题、任务栏显示问题,执行完重启系统还报错执行下一个" 
		"8、V10/SP1-控制面板打不开" 
		"9、V10-关机卡麒麟软件四个字" 
		"0、返回上一级菜单-按“99999”")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) system-repair-boon-taskbar; break;;
                2) system-repair-boon-clean; break;;
                3) system-repair-boon-clean; break;;
				4) system-repair-boon-install; break;;
				5) system-repair-boon-poweroff; break;;
				6) system-repair-boon-caja; break;;
				7) system-repair-boon-mate; break;;
				8) system-repair-boon-contrlmate; break;;
				9) system-repair-boon-qilin; break;;
                0) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-boon-taskbar(){
  home_path
  sudo rm -rf .cache/ .config/ .Xauthority
  sudo systemctl restart lightdm
}
system-repair-boon-clean(){
  sudo apt clean
  sudo apt autoclean          #删/var/cache/apt/archives下deb文件
  sudo apt autoremove          #删不需要的依赖
  sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo dpkg --purge #删软件残留配置--rc开头的文件
  sudo rm -rf /tmp/*             #删tmp缓存
}
system-repair-boon-install(){
  sudo dpkg -P upstart
  sudo dpkg -P firefox
  sudo apt install aptitude
  sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo aptitude install -y
}
system-repair-boon-poweroff(){
  sudo rm /tmp/lock/kylin-update.lock
  sudo apt-get --reinstall install -y kylin-update-manager
  sudo rm /var/cache/apt/archives/lock
  sudo rm /var/lib/dpkg/lock-frontend
  sudo apt install -f
}
system-repair-boon-caja(){
  sudo apt update
  sudo rm -rf .config/
  if [[ $version_flag == 'V10' ]];then
    sudo apt install caja --reinstall
  elif [[ $version_flag == 'V10-SP1' ]];then
    sudo apt install peony --reinstall
  fi
  sudo apt install lightdm --reinstall
  sudo dpkg-reconfigure lightdm
  sudo systemctl enable lightdm
}
system-repair-boon-mate(){
 if [[ $version_flag == 'V10' ]];then
    sudo apt install mate-indicators --reinstall
  fi
}
system-repair-boon-contrlmate(){
  if [[ $version_flag == 'V10' ]];then
    sudo apt install kylin-control-center --reinstall
    sudo kylin-control-center
  elif [[ $version_flag == 'V10-SP1' ]];then
    sudo apt install ukui-control-center --reinstall
    ukui-control-center
  fi
}
system-repair-boon-qilin(){
  sudo sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
  sudo sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
  sudo sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
  sudo sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
}
system-repair-desk-other(){
    while true; do
	    return_to_main=false
        echo "其他问题修复"
		options=(
		"1、V10/SP1--桌面密钥环消除" 
		"2、V10/SP1--ll查看命令不生效--误删.bashrc和.bash_profile文件" 
		"3、V10--尝试增加exfat硬盘支持" 
		"4、V10SP1--关闭执行控制--脚本不能执行--安全中心可手动设置" 
		"5、V10SP1--关闭网络控制--部分应用网络不可用--安全中心可手动设置" 
		"6、V10SP1--关闭应用来源检查--安装软件时的检查--安全中心可手动设置" 
		"7、V10SP1--老版本如2107激活的系统，服务到期提示已过期--V10不要选，此处未作判断" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) system-desk-other-seahorse; break;;
                2) system-desk-other-ll; break;;
                3) sudo apt install exfat-fuse exfat-utils; break;;
				4) sudo setstatus -f exectl off -p; break;;
				5) sudo setstatus -f netctl off -p; break;;
				6) sudo setsignstatus off; break;;
				7) sudo apt install ukui-control-center --reinstall; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-desk-other-seahorse(){
  sudo apt install seahorse -y
  echo -e "$red 三秒后在打开的界面右键点密码下的key，删除即可$none"
  sleep 3
  sudo seahorse
}
system-desk-other-ll(){
  home_path
  sudo cp /etc/skel/.bashrc ./
  sudo chmod 644 .bashrc
  sudo touch .bash_profile
  echo -e "if [ -f ~/.bashrc ]; then\n\t. ~/.bashrc\nfi" | sudo tee .bash_profile
}
system-repair-soft-fix(){
    while true; do
	    return_to_main=false
        echo "系统软件修复"
		options=(
		"1、V10SP1-2203--刻录软件除990-2203外的续刻问题--此处未判断" 
		"2、V10SP1-2303--刻录软件超103字符无法刻录问题" 
		"3、V10/SP1---字体相关问题" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) download_file kelu_xuke deb_zip; break;;
                2) download_file kelu_zifu_2303 deb_zip; break;;
                3) system-soft-fix-fonts; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-soft-fix-fonts(){
    while true; do
	    return_to_main=false
	    options=(
		"1、批量安装，需将ttf文件拷到新建的文件夹下再继续执行" 
		"2、在公司源中安装字体管理器--推荐" 
		"3、V10老版本,没有字体管理器的--离线安装公司开发的老版本字体管理器，新版本有依赖问题" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) system-soft-fix-fonts-fontsowninstall; break;;
                2) sudo apt install -y gnome-font-viewer; break;;
                3) download_file dfonts deb; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-soft-fix-fonts-fontsowninstall(){
  change_root
  desktop_path
  pwd
  sudo mkdir newfonts
  sudo mkdir -p /usr/share/fonts/newfonts
  sudo chmod -R 777 ./newfonts/
  echo
  echo -e "$magenta 请将ttf字体文件拷到newfonts文件夹中再按任意键继续进行操作:"
  return_to_main=true
  echo
  sudo chmod -R 777 ./newfonts/
  sudo cp ./newfonts/* /usr/share/fonts/newfonts/
  sudo chmod -R 777 /usr/share/fonts/newfonts/
  sudo fc-cache /usr/share/fonts/newfonts/
  ls /usr/share/fonts/newfonts/
  echo -e "$red 应该可以用了，重新打开wps，fc相关组件未安装的需要重启下电脑。$none \n"
}
system-repair-dev-fix(){
    while true; do
	    return_to_main=false
        echo "开发盘下修复"
		options=(
		"1、盘无法挂载，需修复" 
		"2、挂载开发盘" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) system-repair-dev-fix-fsck; break;;
                2) system-repair-dev-fix-mount; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-dev-fix-fsck(){
  DEV_UUID=$(blkid | grep "TYPE=\"ext4\"" | awk '{print $2}' | cut -d '"' -f 2)
  if [ -z "$DEV_UUID" ]; then
    echo "无法找到开发盘"
    exit 1
  fi
  # 根据UUID执行fsck命令
  echo "正在对分区 $DEV_UUID 进行fsck修复..."
  fsck -y /dev/disk/by-uuid/$DEV_UUID
}
system-repair-dev-fix-mount(){
  sudo mkdir -p /disk01
  sudo chmod -R 777 /disk01
  sudo mount /dev/nvme0n1p2 /disk01
  echo -e "打开文件系统下disk01文件夹查看"
}
system-repair-update(){
    while true; do
	    return_to_main=false
        echo "系统升级"
		options=(
		"1、V10-2020年的0710等升级到21年的2101" 
		"2、V10-2021年的2101等升级到21年的2107" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) download_file sys_update_v10_0710 deb; break;;
                2) download_file sys_update_v10_2101 deb; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-mabe(){
    while true; do
	    return_to_main=false
        echo "可能非好用的功能"
		options=(
		"1、触摸板滑动方向改为windows一致" 
		"2、校准时间--若有ntp服务" 
		"3、解锁uos#TODU" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) sudo synclient VertScrollDelta=-30; break;;
                2) ntpdate time.windows.com; break;;
				3) system-repair-mabe-unblock_uos; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
system-repair-mabe-unblock_uos(){
  chattr -i /var/lib/deepin/developer-mode/enabled
  rm -rf /var/lib/deepin/developer-mode/enabled
}



# 三、软件商店问题：software_repair
software_repair(){
    while true; do
	    return_to_main=false
        echo "软件商店问题"
		options=(
		"1、修复商店源-解决商店里软件少" 
		"2、更新源提示GPG错误" 
		"3、更新软件源时，提示等待报头一直为0、软件源无法加锁" 
		"4、安装软件提示失败" 
		"5、软件商店报错---如打开商店报0001-0005等代码、dbus服务异常--重装软件商店" 
		"6、软件商店报错---如打开商店报0001-0005等代码、dbus服务异常--不重装软件商店" 
		"7、软件商店打不开---V10-0710等安装新版本商店后打不开--装老版本商店且后续不要升级" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) echo "暂时没写修复商店源"; break;;  # 暂时没写software_repair-update
                2) softcenter_repair soft_GPG; break;;
                3) softcenter_repair soft_lock; break;;
				4) softcenter_repair soft_install_fail; break;;
				5) softcenter_repair soft_wrong_code_soft; break;;
				6) softcenter_repair soft_wrong_code; break;;
				7) softcenter_repair 0710_cantopen; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}



# 四、应用软件：software_app
software_app(){
    while true; do
	    return_to_main=false
        echo "应用软件"
		options=(
		"1、社交-微信、QQ、腾讯会议、蓝信" 
		"2、远程-向日葵、Todesk" 
		"3、字体安装相关--字体管理器、批量安装字体" 
		"4、金山WPS相关--清理金山缓存、安装个人版" 
		"5、影音下载相关--哔哩哔哩、落雪、阿里小白羊" 
		"6、浏览器相关--360等浏览器下载、flash插件下载" 
		"7、解包重新打包--比如安装后没图标的，以及从统信下载的包" 
		"8、安装编译环境，如qt等---暂部分有问题"
		"9、下载制作ISO镜像的工具" 
		"10、下载notepad--"
		"11、easyconnect"
		"12、crossover试用"
		"13、上一级菜单-按“99999”"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) software_app-tencent; break;;  # 暂时没写
                2) software_app-remote; break;;
                3) system-soft-fix-fonts; break;;
				4) software_app-kingsoft; break;;
				5) software_app-fun; break;;
				6) software_app-browser; break;;
				7) software_app-change-deb; break;;
				8) software_app-about-code; break;;
				9) download_file mk_iso deb; break;;
				10) download_file notepad deb; break;;
				11) download_file easyconnect deb; break;;
				12) software_app-crossover; break;;
				13) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-tencent(){
    while true; do
	    return_to_main=false
	    options=(
		"1、微信" 
		"2、QQ" 
		"3、腾讯会议" 
		"4、蓝信" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_app-tencent-wechat; break;;
                2) software_app-tencent-qq; break;;
                3) download_file tencent_metting deb; break;;
				4) download_file lanxin deb; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-tencent-wechat(){
    while true; do
	    return_to_main=false
	    options=(
		"1、在公司源中安装微信---V10/SP1-mips默认安装网页版微信、V10默认安装weixin2.1.4-9、V10SP1默认安装新版微信" 
		"2、V10-Mips--微信禁用gpu--适用于微信闪退及卡顿" 
		"3、V10-Mips--微信登录提示登录失败error、老Mips激活过期后微信不可用--在公司源中修复微信相关依赖" 
		"4、杀老版本微信进程--双击微信图标无反应可尝试" 
		"5、无法扫码--离线安装微信2.1.4-1版本" 
		"6、无法扫码--离线安装微信2.1.9版本" 
		"7、V10-SP1离线安装微信beta版本" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_app-tencent-wechat1; break;;
                2) software_app-tencent-wechat2; break;;
                3) software_app-tencent-wechat3; break;;
				4) software_app-tencent-wechat4; break;;
				5) software_app-tencent-wechat5; break;;
				6) software_app-tencent-wechat6; break;;
				7) software_app-tencent-wechat7; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-tencent-wechat1(){
      sudo apt update
      if [ "$sys_str" == "mips64" ]; then
        sudo apt install -y kylin-activation libkylin-activation wechat
      else
        sudo apt install -y wechat-beta
      fi
}
software_app-tencent-wechat2(){
      sudo cp /usr/share/applications/wechat.desktop /usr/share/applications/wechat.desktop_"$timestamp"
      sudo sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /usr/share/applications/wechat.desktop
      sudo sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /home/"$this_user"/桌面/wechat.desktop
      echo -e "请关闭微信并重新打开微信。$none \n"
}
software_app-tencent-wechat3(){
      sudo tee /etc/apt/sources.list << EOF
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0 main restricted universe multiverse
deb http://archive2.kylinos.cn/deb/kylin/production/PART-V10/custom/partner/V10 default all
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0-fixs main
EOF
      sudo apt update && sudo apt install -y kylin-activation libkylin-activation
}
software_app-tencent-wechat4(){
      sudo killall -9 weixin || sudo killall -9 wechat
}
software_app-tencent-wechat5(){
      download_file 'wx_2.1.4' 'deb'
}
software_app-tencent-wechat6(){
      download_file 'wx_2.1.9' 'deb'
}
software_app-tencent-wechat7(){
      if [ "$sys_str" == "mips64" ]; then
        sudo apt install -y kylin-activation libkylin-activation wechat
      else
        if [[ $version_flag == 'V10' ]];then
          sudo apt install -y weixin zlib1g
        elif [[ $version_flag == 'V10-SP1' ]];then
          download_file 'wechat_beta' 'deb'
        fi
      fi
}
software_app-tencent-qq(){
    while true; do
	    return_to_main=false
	    options=(
		"1、安装新版QQ---推荐" 
		"2、V10老版本qq不出二维码--关ipv6" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_app-tencent-qq-new; break;;
                2) software_app-tencent-ipv6; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-tencent-qq-new(){
      download_file 'tencent_linuxqq' 'deb'
}
software_app-tencent-ipv6(){
      if ! grep -q 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"' /etc/default/grub; then
          sudo sed -i '$ a\GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"' /etc/default/grub
      fi
      if ! grep -q 'GRUB_CMDLINE_LINUX="ipv6.disable=1"' /etc/default/grub; then
          sudo sed -i '$ a\GRUB_CMDLINE_LINUX="ipv6.disable=1"' /etc/default/grub
      fi
      sudo update-grub
      echo -e "执行完了，请重启下系统$none \n"
}
software_app-remote(){
    while true; do
	    return_to_main=false
	    options=(
		"1、公司源中安装向日葵--首选" 
		"2、公司源中安装todesk--首选" 
		"3、安装Todesk的x86和arm版---此软件无mips" 
		"4、老版本离线安装向日葵10.0版---V10MIPS常用，arm有问题也可用这个，最新版本尽量不用" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) sudo apt install sunloginclient; break;;
                2) sudo apt install todesk; break;;
				3) download_file todesk deb; break;;
				4) download_file sunlogin deb; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-kingsoft(){
    while true; do
	    return_to_main=false
	    options=(
		"1、清除wps缓存" 
		"2、备份wps激活文件到桌面" 
		"3、下载wps个人版" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_app-kingsoft-cache-clean; break;;
                2) software_app-kingsoft-desktop; break;;
				3) software_app-kingsoft-gerenban; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-kingsoft-cache-clean(){
      quickstartoffice stop
      home_path
      sudo rm -rf .config/Kingsoft
      sudo rm -rf .local/share/Kingsoft
      quickstartoffice start
}
software_app-kingsoft-desktop(){
      sudo cp  /opt/kingsoft/wps-office/office6/cfgs/oem.ini /home/"$this_user"/桌面/
      sudo chmod 777 /home/"$this_user"/桌面/oem.ini
}
software_app-kingsoft-gerenban(){
      dpkg_wps=$(dpkg -l | grep wps | awk '{print $2}')
      sudo dpkg --force-all --purge $dpkg_wps
}
software_app-fun(){
    while true; do
	    return_to_main=false
	    options=(
		"1、下载哔哩哔哩" 
		"2、下载落雪音乐" 
		"3、下载阿里云盘" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) download_file bilibilidl deb; break;;
                2) download_file lxmusic deb; break;;
				3) download_file aliyunpan deb; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-browser(){
    while true; do
	    return_to_main=false
	    options=(
		"1、尝试给浏览器装flash插件" 
		"2、下载360浏览器" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) sudo apt install -y kylin-flash-plugin; break;;
                2) sudo apt install browser360-cn-stable; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-change-deb(){
  #TODU切换普通用户
  if [[ $(id -u) == 0 ]]; then
    # get_passwd
    # sudo -u $this_user -S <<< "$password"
    echo -e "请用普通用户执行"
    exit;
  fi
  echo -e "先保证这个deb包与你右键打开终端处于同一文件夹下，比如你在桌面右键打开的终端，此deb就该在桌面"
  echo -e "注意deb的包名应与原来一致，比如在uos微信是com.tencent.weixin，在kylin是weixin，就要把package改为weixin。"
  read -r -p "$(echo -e "$magenta 请输入需解包的deb名(建议提前改成比较简单的名:before，不用加deb): $none")" before_name
  read -r -p "$(echo -e "$magenta 请输入解包的文件夹名(如mynewdeb): $none")" mynewdeb_dir
  read -r -p "$(echo -e "$magenta 请输入最终生成的deb包名:after，不用加deb: $none")" after_name
  dpkg-deb -R $before_name.deb $mynewdeb_dir
  cd $mynewdeb_dir
  mkdir -p ./usr/share/
  sed -i '/^Depends:/ s/deepin-elf-verify *(>= *[0-9][^)]*),\{0,1\}//' ./DEBIAN/control
  sed -i 's/,[[:space:]]*$//' ./DEBIAN/control
  find . -type d -name "applications" -not -path "./usr/*" -exec cp -rp {} ./usr/share/ \;
  find . -type d -name "icons" -not -path "./usr/*" -exec cp -rp {} ./usr/share/ \;
  cd ..
  echo -e "如果还有其他要改的，请自行打开control等文件并修改，之后按$yellow任意键$none继续"
  get_pause
  dpkg-deb --build $mynewdeb_dir $after_name.deb
}
software_app-about-code(){
    while true; do
	    return_to_main=false
	    options=(
		"1、安装vscode1.82.2--最新版地址：https://code.visualstudio.com/Download#，需要特定网络" 
		"2、安装qtcreator-可商店直接搜索" 
		"3、安装git"
		"4、安装make\cmake"
		"5、安装g++、gcc、cpp"
		"6、安装qt工具和库--暂有问题"
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) download_file vscode deb; break;;
                2) sudo apt install qtcreator qtcreator-data; break;;
				3) sudo apt install git; break;;
				4) sudo apt install make cmake; break;;
				5) sudo apt install g++ gcc cpp; break;;
				6) sudo apt install qtbase5-dev qt5-qmake qtbase5-dev-tools libqt5printsupport5 libqt5xmlpatterns5-dev; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_app-crossover(){
  change_root
  home_path
  cd ".cxoffice/" || exit
  change_root
  sudo find . -name ".eval" -exec rm -f {} \;
  sudo rm -f {}
}



# 五、打印机软件：software_printer
software_printer(){
    while true; do
	    return_to_main=false
        echo "打印机
		驱动去麒麟官网查https://eco.kylinos.cn/zoology/commercial.html?system_class=1
		佳能基本要去佳能官网查https://www.canon.com.cn/supports/download/sims/search/index"
		options=(
		"1、安装惠普3.16.3" 
		"2、安装惠普3.22.x或最新版" 
		"3、安装佳能2900、3000--arm+mips" 
		"4、奔图打印机驱动-一般去https://www.pantum.cn/support/download/driver/自行下载#TUDOrar未处理" 
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) sudo apt install hp-printer-hplip-3.16.3; break;;  # 暂时没写software_repair-update
                2) sudo apt install hplip; break;;
                3) download_file canon2900 deb; break;;
				4) download_file bentu7105dn deb_zip; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}



# 六、其他功能：software_other
software_other(){
    while true; do
	    return_to_main=false
        echo "其他功能，如查看网速，查找文件、查找安装包；上传文件到ftp、母盘打包镜像"
		options=(
		"1、查看实时网速" 
		"2、查找文件或安装包" 
		"3、上传文件到FTP" 
		"4、解包镜像并生成新镜像"
		"5、增加rc.local"
		"6、杀进程，如输入xunlei\weixin\weichat这样的"
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) software_other-speed; break;;  # 暂时没写software_repair-update
                2) software_other-findfiles; break;;
                3) software_other-uptoftp; break;;
				4) software_other-mkiso; break;;
				5) software_other-addrclocal; break;;
				6) software_other-killprocess; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_other-speed(){
  echo -e " In ------ Out"
  read -r -p "$(echo -e "请输入测试时长（秒）：")" duration
  start_time=$(date +%s)
  while [[ $(date +%s) -lt $((start_time + duration)) ]]; do
    OLD_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==4{print $1}')
    OLD_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==4{print $1}')
    sleep 1
    NEW_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==4{print $1}')
    NEW_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==4{print $1}')
    IN=$(printf "%.1f%s" "$(( ("$NEW_IN" - "$OLD_IN") / 1024 ))" "KB/s")
    OUT=$(printf "%.1f%s" "$(( ("$NEW_OUT" - "$OLD_OUT") / 1024 ))" "KB/s")
    echo "$IN $OUT"
  done
}
software_other-findfiles(){
    while true; do
	    return_to_main=false
	    options=(
		"1、按名称查找文件(区分大小写)" 
		"2、按名称查找文件(不区分大小写)" 
		"3、按文件内容查找(只在home和data目录下查找--原则上用户数据都在这俩目录)"
		"4、按文件内容查找(自定义目录)"
		"5、查找源里的软件包"
		"6、查找本机所有安装的软件包"
		"7、查找本机是否安装软件包--如输入linuxqq看有没有安装qq"
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) findname file_case; break;;
                2) findname file_nocase; break;;
				3) findname file_content; break;;
				4) findname file_own_content; break;;
				5) findname soft_source; break;;
				6) findname soft_local_all; break;;
				7) findname soft_local; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_other-uptoftp(){
    while true; do
	    return_to_main=false
	    options=(
		"1、第一次执行请直接按1打包不成功重试" 
		"2、打包成功，但是因为种种原因没能上传成功请按2" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_other-uptoftp1; break;;
                2) software_other-uptoftp2; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_other-uptoftp1(){
        pack_file
        rename_file
        remote_file
}
pack_file(){
  read -r -p "$(echo -e "请输入要打包文件的起始时间如 2022-01-01 :")" starttime
  read -r -p "$(echo -e "请输入要打包文件的结束时间如 2023-01-01 :")" endtime
	find  /data/ /home/ ! -name '.*' -a ! -regex '.*/\.[^/]*/.*' -type f -print0 -newermt  "$starttime" ! -newermt "$endtime" | xargs -0 tar -czPf /data/test.tar.gz
  echo
	echo -e "已经打包好了，在/data/下，目前叫test.tar.gz"
}
rename_file(){
	read -r -p "$(echo -e "请输入你的文件名:${none}")" name
	echo
	echo -e "这个文件将被改为：${red}${name}.tar.gz ${none}，按任意键继续进行操作:"
  sleep 10
	echo
	echo
	mv /data/test.tar.gz /data/"$name".tar.gz
	chmod 755 /data/"$name".tar.gz
  echo
	echo -e "已经重命名好了，此文件名为：${red}${name}.tar.gz${none}"
}
remote_file(){
  get_pause
	echo
  read -r -p "$(echo -e "请输入服务器IP地址如 192.168.210.5 ")" addr
	echo
  read -r -p "$(echo -e "请输入服务器端地址如 /ftpdata/upload/2021/ ")" addr_home
  echo
	echo -e "请输入服务器密码:"
	echo
  #scp /data/$name.tar.gz  root@192.168.210.5:/ftpdata/upload/2021/
	scp /data/"$name".tar.gz  root"$addr":"$addr_home"
	echo
	echo -e " 已经上传好了，请打开左下角开始菜单，找到FileZilla这个FTP软件查看"
	echo
	rm -rif /data/"$name".tar.gz
  echo
}
software_other-uptoftp1(){
        get_file_name
        remote_file
}
get_file_name(){
	echo
	echo -e "${cyan} 比如说你的数据盘下的文件为：${red}张三.tar.gz${none}${cyan}，则直接输入：${red}张三${none}"
	echo
	read -r -p "$(echo -e " 请输入文件名：")" name
	echo
	echo -e " 要上传的文件名为：${red}${name}.tar.gz ${none}，确定则按任意键继续进行操作:"
	echo
}
software_other-mkiso(){
    while true; do
	    return_to_main=false
	    options=(
		"1、选1解压缩ISO镜像" 
		"2、选2进行iso镜像的封装" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_other-mkiso-unsquashfs_iso; break;;
                2) software_other-mkiso-mksquashfs_iso; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_other-mkiso-unsquashfs_iso(){
  if [ -d "/opt/livecd" ]; then
    rm -rf /opt/livecd/*
  else
    mkdir -p /opt/mnt /opt/livecd /opt/tool
  fi
  read -p "请 输 入 ISO所在绝对路径(此路径下只能有一个iso镜像):" absolute_path
  mount "$absolute_path"/*.iso /opt/mnt/
  cp -rp /opt/mnt/. /opt/livecd/ 
  umount /opt/mnt/
  cd /opt/livecd/casper/
  unsquashfs filesystem.squashfs

  read -p "请 输 入 安 装 包 地 址：" deb_path
  if [ -z "$deb_path" ]; then
    exit 1
  fi
  cp "$deb_path"/*.deb /opt/livecd/casper/squashfs-root/tmp
  echo "$red 如果你看起来退出了当前脚本，则已进入squashfs模式，执行sudo  bash  /tmp/run.sh" 
  echo "然后exit，再重新执行此脚本，选择2 $none" 
  sudo tee /opt/livecd/casper/squashfs-root/tmp/run.sh << EOF
sudo mount -t proc none /proc
sudo mount -t sysfs none /sys
sudo mount -t devpts none /dev/pts
sudo dpkg -i /tmp/*.deb
sudo rm -rf /tmp/* 
sudo umount /proc 
sudo umount /sys 
sudo umount /dev/pts
exit
EOF
  chroot squashfs-root
}
software_other-mkiso-mksquashfs_iso(){
  cd /opt/livecd/casper
  rm filesystem.squashfs
  mksquashfs squashfs-root filesystem.squashfs -comp xz
  printf $(du -sx --block-size 1 squashfs-root |cut -f1) >filesystem.size 
  chattr -R -i squashfs-root

  rm -r squashfs-root
  cd /opt/livecd/
  rm md5sum.txt
  find -type f -print0 | xargs -0 md5sum|grep -v isolinux/boot.cat |tee md5sum.txt
  cd /opt/livecd/
  if [ "$sys_str" == "x86_64" ]; then
    mkisofs -J -r -V "Kylin-Desktop-V10-x86" -cache-inodes -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -o /opt/Kylin-V10-desktop-x86.iso . 
  elif [ "$sys_str" == "aarch64" ]; then
    genisoimage -e boot/grub/efi.img -no-emul-boot -T -J -R -c boot.catalog -hide boot.catalog -V "Kylin-V10-desktop-arm" -o /opt/Kylin-V10-desktop-arm.iso .
  elif [ "$sys_str" == "mips64" ]; then
    mkisofs -b casper/initrd.img -no-emul-boot -T -J -R -c boot.catalog -hide boot.catalog -V "Kylin-V10-desktop-mips64el" -o /opt/Kylin-V10-desktop-mips64el.iso .
  else
    echo "暂不支持" && exit 1
  fi
}
software_other-addrclocal(){
  change_root
  echo -e "\n[Install]\nWantedBy=multi-user.target\n" | sudo tee -a /lib/systemd/system/rc-local.service
  sudo touch /etc/rc.local && chmod 755 /etc/rc.local
  echo -e "#!/bin/bash\n" | sudo tee  /etc/rc.local
  sudo systemctl daemon-reload
  sudo systemctl start rc-local.service
  sudo systemctl enable rc-local.service
  echo -e "接下来可以自己编辑vim /etc/rc.local添加开机启动项了。"
}
software_other-killprocess(){
  read -r -p "$(echo -e "$magenta 请输入想杀到的进程(如xunlei): $none")" proc_name
  ps -ef | awk -v pn="$proc_name" '$0 ~ pn {print $2}' | xargs kill
}



# 七、服务器相关：software_server
software_server(){
    while true; do
	    return_to_main=false
        echo "只针对服务器"
		options=(
		"1、尝试修复yum makecache报错，如error: rpmdb: xxx failed" 
		"2、内网源挂载" 
		"3、FTP服务端--VSFTP安装--安装后使用FillZilla访问" 
		"4、SAMBA安装-只一个账户"
		"5、vnc-server安装"
		"6、做bond"
		"7、openssh改版本号"
		"9、上一级菜单-按“99999”" 
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
            case $REPLY in
                1) software_server-rpm_repair; break;;  # 暂时没写software_repair-update
                2) software_server-net_source; break;;
                3) software_server-ftp_install; break;;
				4) software_server-smb_install; break;;
				5) software_server-vnc_install; break;;
				6) software_server-bond_install; break;;
				7) software_server-openssh_change; break;;
                00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;  # 当用户选择上一级菜单-按“99999”时，返回上一级菜单-按“99999”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_server-rpm_repair(){
  sudo rm -f /var/lib/rpm/__db*
  sudo db_verify /var/lib/rpm/Packages
  sudo rpm --rebuilddb
}
software_server-net_source(){
  read -s -rp "插入U盘的话请按1并手动输入挂载地址，插入光盘则可直接回车：" opt
  case $opt in
    1)
      read -s -rp "请输入挂载地址：" mounted
      MOUNTPOINT=$mounted
      ;;
    *)
      if grep -qs '/dev/sr0' /proc/mounts; then
        MOUNTPOINT=$(grep '/dev/sr0' /proc/mounts | awk '{print $2}')
      else
        mkdir -p /media/root/Kylin-server
        mount /dev/sr0 /media/root/Kylin-server
        MOUNTPOINT=/media/root/Kylin-server
      fi
      ;;
  esac
  mkdir -p /data/Kylin-server
  echo -e "开始复制"
  rsync -a --info=progress2 $MOUNTPOINT/* /data/Kylin-server
  sed -i -e '/\[ks10-adv-os\]/,/enabled = 1/ s|^\(baseurl =.*\)|#\1\nbaseurl=file:///data/Kylin-server|' \
       -e '/\[ks10-adv-updates\]/,/enabled = 1/ s/enabled = 1/enabled = 0/' /etc/yum.repos.d/kylin_x86_64.repo
	yum clean all
  yum makecache
  echo -e "应该是挂载上了"
}
software_server-ftp_install(){
    while true; do
	    return_to_main=false
	    options=(
		"1、安装及配置VSFTP--安装后配置有问题的也可通过此修改" 
		"2、批量添加用户" 
		"按 99999 ---返回上一级菜单"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) software_server-ftp_install-vsftp_install; break;;
                2) software_server-ftp_install-add_ftpuser; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}
software_server-ftp_install-vsftp_install(){
  if vsftpd -v >/dev/null 2>&1; then
      echo "vsftpd 已安装。"
  else
      yum install -y vsftpd >/dev/null 2>&1
      if [ $? -eq 0 ]; then
          echo "vsftpd 成功安装."
          systemctl start vsftpd >/dev/null 2>&1
          systemctl enable vsftpd >/dev/null 2>&1
          echo "vsftpd 服务已启动，并已开机自启。"
      else
          echo "vsftpd 安装失败，看看源是不是有问题"
          exit 1
      fi
  fi
  firewall-cmd --permanent --zone=public --add-service=vsftpd
  firewall-cmd --reload

  # 配置vsftpd
  read -p "是否配置vsftp配置文件： [yes/no] " answer
  if [[ "$answer" =~ ^[Yy][Ee][Ss]$ ]]; then
    config=/etc/vsftpd/vsftpd.conf
    cp $config $config_$timestamp

    sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' $config
    #sed -i 's/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g' $config
    sed -i 's/#chown_uploads=YES/chown_uploads=YES/g' $config
    sed -i 's/#async_abor_enable=YES/async_abor_enable=YES/g' $config
    sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/g' $config
    sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/g' $config
    sed -i 's/#ftpd_banner/ftpd_banner/g' $config
    sed -i 's/#chroot_local_user=YES/chroot_local_user=NO/g' $config
    sed -i 's/#chroot_list_enable=YES/chroot_list_enable=YES/g' $config
    sed -i 's/#chroot_list_file/chroot_list_file/g' $config

    # 定义要添加的配置项数组
    config_items=(
        "pasv_min_port=4500"
        "pasv_max_port=5000"
        "allow_writeable_chroot=YES"
    )

    # 遍历数组，分别判断每个配置项是否已经存在
    for item in "${config_items[@]}"; do
        if grep -q "$item" "$config"; then
            echo "配置项 '$item' 已存在，无需添加。"
        else
cat >> "$config" << EOF
$item
EOF
            echo "配置项 '$item' 添加成功。"
        fi
    done
  fi

  # 重启vsftpd服务
  systemctl restart vsftpd >/dev/null 2>&1
  echo "vsftpd 服务已重启."
  software_server-ftp_install-add_ftpuser
}
software_server-ftp_install-add_ftpuser(){
  ftpConfig=/etc/vsftpd
  echo "如下配置完最终效果就是：用户yd01的文件存放在/data/ftp/yd01: "
  read -p "请输入ftp文件存放的根目录，比如/data/ftp：" ftpPath
  if [ ! -d "$ftpPath" ]; then
    echo "ftp目录不存在，创建对应目录$ftpPath: "
    mkdir -p "$ftpPath"
    chmod -R 700 "$ftpPath"
  fi

  while true; do
    read -p "请输入ftp用户名，直到输入done结束配置：" user_name
    if [[ "$user_name" == "done" ]]; then
        break
    fi
    if id "$user_name" >/dev/null 2>&1; then
      echo "用户名已存在，请重新输入。"
    else
      echo "添加 vsftp 账号： $user_name"
      useradd -s /sbin/nologin -d "$ftpPath/$user_name" $user_name
      chown -R $user_name:$user_name "$ftpPath/$user_name"
      while true; do
        echo "请输入vsftp账号密码，注意密码要有复杂度，要大于8字符且三个类型："
        echo "比如：xz123@qq.com，得复杂一些，密码不可见，盲输入"
        passwd $user_name
        if [ $? -eq 0 ]; then
          echo "密码设置成功。"
          break
        else
          echo "密码设置失败，请重新输入。"
        fi
      done

      touch $ftpConfig/chroot_list
      echo "$user_name" >> $ftpConfig/chroot_list
    fi
  done

  systemctl restart vsftpd >/dev/null 2>&1
}
software_server-smb_install(){
  if smbd --version >/dev/null 2>&1; then
    echo "samba 已安装。"
  else
    yum install -y samba >/dev/null 2>&1
    if [ $? -eq 0 ]; then
      echo "samba 成功安装."
    else
      echo "samba 安装失败，看看源是不是有问题"
      exit 1
    fi
  fi
  cp /etc/samba/smb.conf /etc/samba/smb.conf.bak_$timestamp

  read -p "请输入samba文件存放的位置：" smb_dir
  mkdir -p $smb_dir
  read -p "请输入samba用户：" smb_user
  useradd $smb_user
  echo -e "samba123@qq.com\nsamba123@qq.com" | smbpasswd -a $smb_user
  echo -e "samba默认密码是：samba123@qq.com，需要的话password $smb_user 自行修改密码"

  cat << EOF > /etc/samba/smb.conf
[global]
   workgroup = WORKGROUP
   server string = Samba Server %v
   netbios name = samba_server
   security = user
   map to guest = bad user
   dns proxy = no

[samba_share]
   comment = Samba Share
   path = $smb_dir
   browsable = yes
   guest ok = no
   read only = no
   valid users = $smb_user
EOF
  
  firewall-cmd --permanent --zone=public --add-service=samba
  firewall-cmd --reload
  systemctl start smb >/dev/null 2>&1
  systemctl start nmb >/dev/null 2>&1
  systemctl enable smb >/dev/null 2>&1
  systemctl enable nmb >/dev/null 2>&1
  echo -e "Windows请访问\\ip，举例\\192.168.59.168，Linux请访问smb://ip，如smb://192.168.59.168"
  get_pause
}
software_server-vnc_install(){
  yum install tigervnc-server -y
  cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
  vncuser='root'
  read -s -rp "请 输 入 用 户 名，默 认 root,用户提前在图形化建好：" vncuser
  if [ "$vncuser" == "root" ]; then
    sed -i 's|/home/<USER>|/root|g' /etc/systemd/system/vncserver@:1.service
    sed -i "s|<USER>|$vncuser|g" /etc/systemd/system/vncserver@:1.service
  else
      sed -i "s|<USER>|$vncuser|g" /etc/systemd/system/vncserver@:1.service
  fi
  echo "接下来输入vnc密码，此密码8位且最好复杂点，比如Q!W@e3as这样。"
  vncpasswd
  systemctl daemon-reload
  systemctl start vncserver@:1.service
  systemctl enable vncserver@:1.service
}
software_server-bond_install(){
  device_names=$(nmcli device | awk '$2 == "ethernet" {print $1}')
  echo "可用的网络设备："
  for name in $device_names; do
    echo "$name"
  done
  systemctl restart NetworkManager
	systemctl enable NetworkManager
	read -p "请输入你要做的bond名称，如bond0：" bond_devices

	nmcli connection add type bond con-name $bond_devices ifname $bond_devices bond.options "mode=active-backup,miimon=100" ipv4.method disabled ipv6.method disabled autoconnect yes
	
	read -p "请输入要绑定的设备号（上面列出来的，请输入第一个）：" bond1_devices
	read -p "请输入要绑定的设备号（上面列出来的，请输入第二个）：" bond2_devices
	mv /etc/sysconfig/network-scripts/ifcfg-$bond1_devices /etc/sysconfig/network-scripts/ifcfg-$bond1_devices.$timestamp
	mv /etc/sysconfig/network-scripts/ifcfg-$bond2_devices /etc/sysconfig/network-scripts/ifcfg-$bond2_devices.$timestamp
	nmcli connection add type ethernet ifname $bond1_devices master $bond_devices autoconnect yes
	nmcli connection add type ethernet ifname $bond2_devices master $bond_devices autoconnect yes

	read -p "请业务口ipv4地址：如x.x.11.x/27: " ipv4_num
	read -p "请业务口ipv4地址：如x.x.11.x/27: " ipv4_gateway
	nmcli connection modify $bond_devices ipv4.method manual ipv4.addresses $ipv4_num  ipv4.gateway $ipv4_gateway
	nmcli connection up bond-slave-$bond1_devices
	nmcli connection up bond-slave-$bond2_devices
	nmcli connection up $bond_devices
}
software_server-openssh_change(){
#!/bin/bash

# 查看版本号
sshd_version=$(sshd -V 2>&1 | grep -oP 'OpenSSH_\K[^ ]+' | cut -d'p' -f1)
echo "当前SSHD版本号: $sshd_version"
ssh_version=$(ssh -V 2>&1 | grep -oP 'OpenSSH_\K[^ ]+' | cut -d'p' -f1)
echo "当前SSH版本号: $ssh_version"

# 查找文件位置
sshd_path=$(which sshd)
echo "SSH文件位置: $sshd_path"
ssh_path=$(which ssh)
echo "SSH文件位置: $ssh_path"

# 查看文件中的版本号
file_version=$(strings "$sshd_path" | grep "OpenSSH_$sshd_version")
echo "文件中的版本号: $file_version"
file_version1=$(strings "$ssh_path" | grep "OpenSSH_$ssh_version")
echo "文件中的版本号: $file_version1"


# 备份SSH文件（另一个备份）
backup_date=$(date "+%Y%m%d%H%M")
backup_path="/usr/sbin/sshd-$backup_date"
cp "$sshd_path" "$backup_path"
echo "已备份SSH文件到 $backup_path"
backup_path1="/usr/sbin/ssh-$backup_date"
cp "$ssh_path" "$backup_path1"
echo "已备份SSH文件到 $backup_path1"

# 手动硬修改版本号
read -p "请输入你想改的openssh的版本号（比如9.7或9.8）: " new_version
sed -i "s/OpenSSH_$sshd_version/OpenSSH_${new_version}/g" "$sshd_path"
sed -i "s/OpenSSH_$ssh_version/OpenSSH_${new_version}/g" "$ssh_path"
echo "版本号已修改为 OpenSSH_$new_versionp1和OpenSSH_$new_version"

# 验证修改后的版本号
modified_version=$(strings "$sshd_path" | grep "OpenSSH_$new_version")
echo "验证修改后的版本号: $modified_version"
modified_version1=$(strings "$ssh_path" | grep "OpenSSH_$new_version")
echo "验证修改后的版本号: $modified_version1"

systemctl restart sshd
}







# 以下为李林自写的脚本
# 获取当前用户用户名
username=`whoami`


peter1(){
sudo chgrp ${username} /usr/bin/dumpcap
sudo chmod 4755 /usr/bin/dumpcap
ls -l /usr/bin/dumpcap
echo "已设置wireshark软件被所有用户可使用"
}

peter2(){
cd /home/${username}
if  [  -f  ".Xauthority"  ];  then
      xauthority_owner=$(ls  -l  .Xauthority  |  awk  '{print  $3}')
      #  比较当前用户和.Xauthority文件的所有者
      if  [  "${username}"  =  "$xauthority_owner"  ];  then
	  echo  ".Xauthority  文件属于当前用户  ${username}."
      else          echo  ".Xauthority  文件不属于当前用户。"
	  echo  "当前用户:  ${username}"
	  echo  ".Xauthority  文件所有者:  $xauthority_owner"
      fi
	  else      echo  ".Xauthority  文件不存在。"
fi
rm -rf .cache .config
sudo systemctl restart lightdm
}

peter3(){
sudo gpasswd -a ${username} nopasswdlogin
echo "已设置 ${username} 用户开机免密登录 "
}

peter4(){
if sudo grep -q "^autologin-user=" "/etc/lightdm/lightdm.conf"; then
    sudo sed -i "s/^autologin-user=.*/autologin-user=${username}/" "/etc/lightdm/lightdm.conf"
else
    sudo echo "autologin-user=${username}" | sudo tee -a "/etc/lightdm/lightdm.conf" > /dev/null
fi
if sudo grep -q "^autologin-user-timeout=" "/etc/lightdm/lightdm.conf"; then
    sudo sed -i "s/^autologin-user-timeout=.*/autologin-user-timeout=0/" "/etc/lightdm/lightdm.conf"
else
    sudo echo "autologin-user-timeout=0" | sudo tee -a "/etc/lightdm/lightdm.conf" > /dev/null
fi
echo "自动登录已设置为用户 ${username}。请重启系统以应用更改。"
}

peter5(){
#!/bin/bash
sudo su
# 提示用户输入变量值
read -p "请输入要创建的本地数据目录路径（例如：/localdata）: " LOCALDATA
fdisk  -l
read -p "请根据上述结果输入要分区的磁盘设备名（例如：/dev/sdb）: " DISK
# 创建目录
mkdir -p $LOCALDATA
# 分区磁盘
parted $DISK --script mklabel gpt mkpart primary xfs 0% 100% quit
# 创建物理卷
pvcreate $DISK"1"
# 创建卷组
vgcreate data_vg $DISK"1"
# 创建逻辑卷
lvcreate -l 100%FREE -n data_lv data_vg
# 格式化逻辑卷
mkfs.xfs /dev/data_vg/data_lv
# 挂载逻辑卷
mount /dev/data_vg/data_lv $LOCALDATA
# 获取逻辑卷的UUID
LV_UUID=$(lsblk -no UUID /dev/data_vg/data_lv)
# 将UUID写入/etc/fstab
echo "UUID=$LV_UUID $LOCALDATA xfs defaults 0 0" >> /etc/fstab
echo "操作完成。逻辑卷的UUID已写入/etc/fstab，系统将在启动时自动挂载。"
}

peter6(){
script_name=`basename $0`
if [ "$(id -u)" -ne "0" ]; then
	echo -e "\033[1;31mUsage: sudo ./$script_name\033[0m" 1>&2
	exit 1
fi
sudo apt update
if [ $? -ne 0 ]; then
	echo -e "\033[31m请确保机器已联网并能正常运行sudo apt update命令\033[0m"
	exit 1
fi
uninstall1="hplip hplip-data hplip-gui libhpmud0 libsane-hpaio printer-driver-hpcups printer-driver-hpijs printer-driver-postscript-hp printer-driver-all-enforce hplip-doc hpijs-ppds hp-ppd"
install1="hplip-data hplip-gui libhpmud0 libsane-hpaio printer-driver-hpcups printer-driver-hpijs printer-driver-postscript-hp printer-driver-all-enforce hpijs-ppds hplip-doc"
os_version=`head -n1 /etc/kylin-build |grep -c "V10-SP1"`
if [ $os_version -eq 1 ]; then
	hplip_version=`apt list -a hplip 2>/dev/null |awk '$2~"3[.]20.*" {print $2}' |uniq`
	uninstall="hp-printer-hplip-3.20.3 $uninstall1"
	install="hp-printer-hplip-3.20.3 hplip=$hplip_version $install1"
else
	hplip_version=`apt list -a hplip 2>/dev/null |awk '$2~"3[.]16.*" {print $2}' |uniq`
	uninstall="hp-printer-hplip-3.16.3 $uninstall1 kylin-printer-driver"
	install="hp-printer-hplip-3.16.3 hplip=$hplip_version $install1"
fi
for i in $uninstall
do
	if dpkg -l |grep $i &>/dev/null; then
		:
	else
		uninstall=`echo $uninstall |sed "s/$i//g"`
	fi
done
apt remove -y $uninstall
dpkg -P $uninstall
apt install -y $install
if [ $? -eq 0 ]; then
	systemctl restart cups
	echo -e "\033[32mhplip版本已成功降级！\033[0m"
fi
}

peter7(){
#!/bin/bash
# 检查是否以root用户运行
if [ "$(id -u)" -ne 0 ]; then
  echo "请以root用户运行此脚本。"
  exit 1
fi
# 列出所有分区
echo "以下是当前系统的分区情况："
lsblk
# 提示用户输入根文件系统分区
read -p "请输入根文件系统分区（例如 /dev/sda5）: " ROOT_PARTITION
# 挂载根文件系统
mount $ROOT_PARTITION /mnt
if [ $? -ne 0 ]; then
  echo "挂载根文件系统失败，请检查分区是否正确。"
  exit 1
fi
# 挂载必须的虚拟文件系统
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /run /mnt/run
# 切换到根文件系统环境
chroot /mnt << 'EOF'
# 更新软件包列表
apt update
# 重新安装内核
apt install --reinstall -y linux-image-$(uname -r)
# 重新安装GRUB
apt install --reinstall -y grub-pc
# 重新生成GRUB配置文件并安装到引导设备
update-grub
grub-install /dev/sda
# 检查GRUB配置文件是否存在
if [ -e /boot/grub/grub.cfg ]; then
  echo "GRUB配置文件生成成功。"
  cat  /boot/grub/grub.cfg
else
  echo "GRUB配置文件生成失败，请检查错误。"
fi
exit
EOF
# 卸载所有挂载的文件系统
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt/run
umount /mnt
# 提示用户重启系统
echo "操作完成，请重启系统。"
}

peter8(){
sudo apt update
sudo apt install --fix-broken
sudo apt install -f
read -p "请选择是否重装软件商店：(y或n，Y或N)" orinstall
# 检查变量orinstall是否为y或Y
if [[ "$orinstall" == "y" || "$orinstall" == "Y" ]]; then
    sudo apt install -y kylin-software-center --reinstall
else
    echo "不重装软件商店"
fi
sudo rm /var/lib/dpkg/updates/*
sudo rm -rf /var/lib/apt/lists/*
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cache/apt/archives/lock
sudo dpkg --configure -a
sudo apt update
echo "已完成软件商店修复，请执行自己的操作"
}

peter9(){
sudo mkdir  -p  /usr/share/fonts/xinziti
read -p "请输入ttf文件全路径，例如：/data/TimesNewRomanPSBoldMT.ttf
或者ttf文件跟kylin-peter.sh脚本在一个路径下 " zitiinstall
sudo cp  ${zitiinstall}  /usr/share/fonts/xinziti/
sudo chmod  755  /usr/share/fonts/xinziti/
sudo chmod  644  /usr/share/fonts/xinziti/*
sudo fc-cache  /usr/share/fonts/xinziti/
echo  "已成功安装字体${zitiinstall}"
}


peter(){
    while true; do
	    return_to_main=false
	    options=(
		"按 1 --桌面--解决wireshark普通用户运行抓包报错的问题---函数peter1"
		"按 2 --桌面--登录用户弹回登录界面---函数peter2"
		"按 3 --桌面--设置桌面用户免密登录---函数peter3"
		"按 4 --桌面--设置开机普通用户自动登录---函数peter4"
		"按 5 --服务器--单个磁盘一键分区给/data---函数peter5"
		"按 6 --桌面--惠普打印机驱动3.20.3降级3.16.3---函数peter6"
		"按 7 --桌面--V10-sp1误删除boot分区恢复脚本---函数peter7"
		"按 8 --桌面--商店报0001-0005等代码、dbus服务异常---函数peter8"
		"按 9 --桌面--安装ttf字体---函数peter9"
		"按 00000 ---返回主菜单")
        select option in  "${options[@]}"; do
        	case $REPLY in
                1) peter1; break;;
                2) peter2; break;;
				3) peter3; break;;
				4) peter4; break;;
				5) peter5; break;;
				6) peter6; break;;
				7) peter7; break;;
				8) peter8; break;;
				9) peter9; break;;
				10) peter10; break;;
				11) peter11; break;;
				12) peter12; break;;
				13) peter13; break;;
				14) peter14; break;;
				15) peter15; break;;
				16) peter16; break;;
				00000) return_to_main=true; break;;   # 返回主菜单-按“00000”
                99999) return;;   # 返回主菜单-按“00000”
                *) echo "无效的选项。请重试。"; continue;;  # 处理无效输入，提示重试
            esac
        done

        # 检查是否需要返回主菜单-按“00000”
        if $return_to_main; then
            break
        fi
    done
}


# 通过显示主菜单来启动脚本
main_menu
